package com.catazy.module_project.repository

import com.catazy.module_project.bean.ArticleData
import com.catazy.module_project.bean.ArticleDetail
import com.catazy.module_project.bean.ArticleDetailWithTag
import com.catazy.module_project.bean.ProjectBean
import com.catazy.module_project.bean.Tag
import com.catazy.wanandroid.common_base.bean.HttpResult
import dagger.hilt.android.scopes.ActivityRetainedScoped
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
 * 作者: Tao
 * 日期: 2024/5/7
 * 时间: 10:00
 * 描述: 项目仓库
 */
@ActivityRetainedScoped
class ProjectRepository @Inject constructor(
    private val remoteRepository: ProjectRemoteRepository,
    private val localRepository: ProjectLocalRepository
) {

    fun getProjectTree(): Flow<HttpResult<List<ProjectBean>>> {
        return remoteRepository.getProjectTree()
    }

    fun getProjectList(id: Int, page: Int): Flow<HttpResult<ArticleData>> {
        return remoteRepository.getProjectList(id, page)
    }

    fun insertProjectTree(projectBean: List<ProjectBean>) {
        localRepository.insertProjectTree(projectBean)
    }

    fun getProjectTreeFromDB(): Flow<List<ProjectBean>> {
        return localRepository.getProjectTree()
    }

    fun insertProjectArticles(articleDetail: List<ArticleDetail>) {
        localRepository.insertProjectArticle(articleDetail)
    }

    fun getProjectArticlesFromDB(): Flow<MutableList<ArticleDetail>> {
        return localRepository.getProjectArticles()
    }

    fun getTagsFromDB(): Flow<List<Tag>> {
        return localRepository.getTags()
    }

    fun getArticleDetailWithTagFromDB(): Flow<MutableList<ArticleDetailWithTag>> {
        return localRepository.getArticleDetailWithTag()
    }

    fun deleteArticleById(articleId: String) {
        localRepository.deleteArticleById(articleId)
    }

    suspend fun downloadFile(url: String, path: String) {
        localRepository.downloadFile(url, path)
    }
}